angular.module('App.router', ["ui.router"])

    .config(['$stateProvider', '$urlRouterProvider', '$httpProvider', function ($stateProvider, $urlRouterProvider, $httpProvider) {
        $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
        $httpProvider.interceptors.push('HttpInterceptor');
        $httpProvider.interceptors.push('AuthInterceptor');

        $stateProvider

            .state('home', {
                url: '/home',
                templateUrl: 'views/home.html',
                controller: 'homeCtrl'
            })
            .state('login', {
                url: '/login',
                templateUrl: 'views/login.html',
                controller: 'loginCtrl'
            })
            .state('forgetPwd', {
                url: '/forgetPwd',
                templateUrl: 'views/forgetPwd.html',
                controller: 'forgetPwdCtrl'
            })
            .state('register', {
            	url: '/register',
                templateUrl: 'views/register.html',
                controller: 'registerController',
	        	resolve: {
	                 deps: ['$ocLazyLoad', function ($ocLazyLoad) {
	                     return $ocLazyLoad.load({
	                         name: 'App',
	                         insertBefore: '#ng_load_plugins_before',
	                         files: [
	                             'js/controllers/registerController.js'
	                         ]
	                     });
	                 }]
	        	}
            })
            .state('instruction', {
                url: '/instruction',
                templateUrl: 'views/instruction.html',
                controller: 'instructionCtrl',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/instructionController.js'
                            ]
                        });
                    }]
                }
            })
            //.state('research', {
            //    url: '/research',
            //    templateUrl: 'views/research.html',
            //    controller: 'researchCtrl'
            //})
            .state('research', {
                url: '/research',
                templateUrl: 'views/research.html',
                controller: 'researchController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/researchController.js'
                            ]
                        });
                    }]
                }
            })
            .state('customerLines', {
                url: '/customer/lines/:planStatus',
                params: {planStatus:null},
                templateUrl: 'views/customer_lines.html',
                controller: 'customerLinesController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/customerLinesController.js'
                            ]
                        });
                    }]
                }
            })
            .state('booking', {
                url: '/booking/:lineId/:planStatus',
                params: {lineId: null,planStatus:null},
                templateUrl: 'views/booking.html',
                controller: 'bookingController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/bookingController.js'
                            ]
                        });
                    }]
                }
            })
            .state('booking.plan', {
                url: '/plan',
                templateUrl: 'views/booking_plan.html',
                controller: 'bookingPlanController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/bookingPlanController.js'
                            ]
                        });
                    }]
                }
            })
            .state('booking.date', {
                url: '/date',
                templateUrl: 'views/booking_date.html',
                controller: 'bookingDateController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'lib/calendar_m.js',
                                'js/controllers/bookingDateController.js'
                            ]
                        });
                    }]
                }
            })
            .state('booking.passenger', {
                url: '/passenger',
                templateUrl: 'views/booking_passenger.html',
                controller: 'bookingPassengerController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/bookingPassengerController.js'
                            ]
                        });
                    }]
                }
            })
            .state('booking.confirm', {
                url: '/confirm',
                auth:true,
                templateUrl: 'views/booking_confirm.html',
                controller: 'bookingConfirmController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/bookingConfirmController.js'
                            ]
                        });
                    }]
                }
            })
            .state('notice', {
                url: '/notice',
                templateUrl: 'views/notice.html',
                controller: 'noticeController',
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/noticeController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user', {
                url: '/user',
                templateUrl: 'views/my.html',
                controller: 'myController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.info', {
                url: '/info',
                templateUrl: 'views/my_info.html',
                controller: 'myInfoController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myInfoController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.updatePwd', {
                url: '/updatePwd',
                templateUrl: 'views/my_updatePwd.html',
                controller: 'myUpdatePwdController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myUpdatePwdController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.unPays', {
                url: '/orders/unpay',
                templateUrl: 'views/my_unpay_orders.html',
                controller: 'myUnpayOrdersController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myUnpayOrdersController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.hadPays', {
                url: '/orders/hadpay',
                templateUrl: 'views/my_hadpay_orders.html',
                controller: 'myHadpayOrdersController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myHadpayOrdersController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.order', {
                url: '/order/:orderId',
                params: {orderId: null},
                templateUrl: 'views/my_order_detail.html',
                controller: 'myOrderDetailController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myOrderDetailController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.orderPay', {
                url: '/order/pay/:orderId/:confirm',
                params: {orderId: null,confirm : null},
                templateUrl: 'views/my_order_pay.html',
                controller: 'myOrderPayController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myOrderPayController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.orderRefund', {
                url: '/order/refund/:orderId',
                params: {orderId: null},
                templateUrl: 'views/my_order_refund.html',
                controller: 'myOrderRefundController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myOrderRefundController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.orderBacks', {
                url: '/orders/orderBacks',
                templateUrl: 'views/my_order_backs.html',
                controller: 'myOrderBacksController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myOrderBacksController.js'
                            ]
                        });
                    }]
                }
            })
            .state('user.orderBackDetail', {
                url: '/orderBack/:orderBackId',
                params: {orderId: null},
                templateUrl: 'views/my_order_back_detail.html',
                controller: 'myOrderBackDetailController',
                auth:true,
                resolve: {
                    deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            name: 'App',
                            insertBefore: '#ng_load_plugins_before',
                            files: [
                                'js/controllers/myOrderBackDetailController.js'
                            ]
                        });
                    }]
                }
            })
        ;

        // if none of the above states are matched, use this as the fallback
        // $urlRouterProvider.otherwise('/login');
        $urlRouterProvider.otherwise(function ($injector, $location) {
            $location.path('/home');
        });

    }])
;

